package com.blast.cn.persenter.splash

import android.view.View
import com.blast.cn.R
import com.wxl.common.base.WorkPresenter
import com.wxl.common.util.SystemUtil
import kotlinx.android.synthetic.main.activity_splash_layout.view.*

class TimeSettingsPresenter : WorkPresenter() {

    override fun onStartDoWork(vararg args: Any) {
        rootView.splashCheckDesTextView.text = "正在设置时间..."
        try {
            if (!SystemUtil.isTimeZoneAuto(rootView.context)) {
                SystemUtil.setAutoTimeZone(rootView.context, 1)
            }
            if (!SystemUtil.isTimeAuto(rootView.context)) {
                SystemUtil.setAutoDateTime(rootView.context, 1)
            }
            if (!SystemUtil.is24Hour(rootView.context)) {
                SystemUtil.set24Hour(rootView.context)
            }
            rootView.splashCheckDesTextView.text = "设置时间成功！"
            doNext()
        } catch (e:Exception){
            e.printStackTrace()
            rootView.splashStartBtn.visibility = View.VISIBLE
            rootView.splashStartBtn.isEnabled = true
            rootView.splashCheckDesTextView.text = "时间设置失败！"
            rootView.splashCheckDesTextView.setTextColor(getResColor(R.color.image_selector_red))
        }
    }
}